﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Data.SqlClient;

namespace Xiaozilang_Ordering_System
{

    public partial class AddMoney2 : Form
    {
        DataTable dt = new DataTable();

        
        public AddMoney2()
        {
            InitializeComponent();
        }


        public AddMoney2(string addmoney)
        {
            InitializeComponent();
            Money.Text = addmoney;
        }
        private void AddMoney2_Load(object sender, EventArgs e)
        {
            //AddMoney addmoney = new AddMoney();
            //文字背景设为透明
            label1.BackColor = Color.Transparent;
            label2.BackColor = Color.Transparent;
            Money.BackColor = Color.Transparent;
            //Money.Text =;
        }

        private void Yes_Click(object sender, EventArgs e)
        {
            bool result = false;
            //string sql = string.Format("select * from User1 where UStel='{0}'",denglu.tel);
            string sql = string.Format("select * from User1 where userID='{0}' ", Shopping_Cart .UserJudge);

            dt = DBHelper.SelectByAdapter(sql);

            while (Convert.ToString(dt.Rows[0]) != null)
            {
                string phonenum = Convert.ToString(dt.Rows[0]["UStel"]);
                string password = Convert.ToString(dt.Rows[0]["pentPwd"]);
                if (phonenum.Equals(denglu.tel) && password.Equals(AddPwd.Text))
                {
                    sql = string.Format("update User1 set USMoney=USMoney+{0} where userID='{1}'", Money.Text, Shopping_Cart.UserJudge);
                    bool reader = DBHelper.GetNonQuery(sql);
                    MessageBox.Show("充值成功");
                    int id = int.Parse(Convert.ToString(dt.Rows[0]["userID"]));
                    sql = string.Format("insert into Recharge (OrderID,RechargeTime,RechargeMoney)" +
                        "values('{0}','{1}','{2}')", id, DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"), Money.Text);
                    bool re = DBHelper.GetNonQuery(sql);
                    Close();
                    client cl = new client();
                    cl.Show();
                    /*DialogResult dr = MessageBox.Show("是否退出?", "提示:", MessageBoxButtons.OKCancel, MessageBoxIcon.Information);
                     if (dr == DialogResult.OK)   //如果单击“是”按钮
                     {
                         System.Environment.Exit(0);
                     }
                     else if (dr == DialogResult.Cancel)
                     {
                                         //不执行操作
                     }*/
                }
                else
                {
                    MessageBox.Show("支付密码错误！", "提示");
                    AddPwd.Focus();
                    AddPwd.SelectAll();
                }
                break;
            }

        }

        private void No_Click(object sender, EventArgs e)
        {
            AddMoney AM = new AddMoney();
            AM.Show();
            Close();

        }
    }
}
